import java.util.Scanner;

class Assignment6G
{
	public static void main (String[] args)
	{
		 int total;
         int number;
         int originalNumber;
         int oneCounter=0;
         int twoCounter=0;
         int choice;
         int digit;
         int totalCount=0;
         Scanner input = new Scanner (System.in);
         System.out.println("This program will determine how many numbers have 1 more 1 than 2's ");
         do
			{
        	 totalCount=0;
				 System.out.println("Please type in a number ");
		         total=input.nextInt();
		         
		         for (originalNumber=1; originalNumber<=total; originalNumber++)
		         {       oneCounter=0;
		                 twoCounter=0;
				         number=originalNumber;
						do  //get the digits
						{
							digit=number%10;
							number=number/10;
							if (digit==1)
								oneCounter=oneCounter+1;
							else if (digit==2)
									twoCounter=twoCounter+1;
							
						}while(number >0);
						if (oneCounter-twoCounter==1)	
						{
							System.out.printf("The number %d has one more 1 than 2\n", originalNumber);
							 totalCount=totalCount+1;
						}
						else	
								 System.out.printf("The number %d does not work\n", originalNumber);
		         } 	 
		         System.out.printf("The number of numbers with more 1 than 2 is %d\n", totalCount); 
				System.out.println("Would you like to continue ? (0-no/1-yes) ");
		         choice = input.nextInt();
			}while (choice != 0);
		          
	  
	}
} 